package com.ly.other.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OtherDo {

    @RequestMapping("other")
    String other(HttpServletRequest request) {
        return "other " + request.getServerPort();
    }

    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("sendMsg")
    public String sendMsg(String msg){
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("work.queue", msg + " " + i);
        }
        return "消息发送成功!";
    }

    @RequestMapping("topicMsg")
    public String topicMsg(String msg, String key){
        rabbitTemplate.convertAndSend("topicEx", key, key + " => " + msg );
        return "消息发送成功!";
    }

}
